<?php
/**
 * Formulaire de réservation
 * 
 * @package zfbook
 * @package form
 */
class Zfbook_Form_Reservation extends Zend_Form
{
    /**
     * Initialisation du formulaire (méthode obligatoire)
     *
     * @return Zend_Form
     */
    public function init()
    {
        $roomModel         = new TRoom();
        $rooms             = $roomModel->fetchAll();
        $roomsTab          = array();
        $placeString       = 'places';
        foreach ($rooms as $room) {
            $roomsTab[$room->id] = $room->name . ' (' . $room->capacity . ' ' . $placeString . ')';
        }
        
        // Liste déroulante des salles (méthode avec setters)
        // déclaration, options, validateurs et filtres
        $roomSelect = new Zend_Form_Element_Select('id_room');
        $roomSelect->setMultiOptions($roomsTab);
        $roomSelect->setLabel("Salle :");
        $roomSelect->setRequired(true);
        $roomSelect->addValidator(new Zend_Validate_Int());
        $this->addElement($roomSelect);

        // Champ texte "usage" (méthode simple avec setters)
        $usage = new Zend_Form_Element_Text('usage');
        $usage->addFilter(new Zfbook_Filter_StripSlashes());
        $usage->addValidator(new Zend_Validate_StringLength(0, 25));
        $usage->setLabel("Utilisation :");
        $usage->setRequired(true);
        $this->addElement($usage);
        
        // Paramètres de dates
        $datePattern = 'YYYY-MM-DD HH:mm:ss';
        $dateValidator = new Zend_Validate_Date($datePattern, 'fr_FR');

        // Champ date de début
        $options = array();
        $options['label']      = "Du :";
        $options['validators'] = array($dateValidator);
        $options['required']   = true;
        $options['filters']    = array(new Zfbook_Filter_StripSlashes());
        $this->addElement('text', 'date_begin', $options);

        // Champ date de fin
        $options['label'] = "Au :";
        $this->addElement('text', 'date_end', $options);

        // captcha
        /*$captchaOptions['label'] = $this->getTranslator()->translate("Retapez cette phrase à l'envers :");
        $captchaOptions['captcha'] = array('captcha' => 'Dumb', 'wordLen' => 6, 'timeout' => 300);
        $captcha = new Zend_Form_Element_Captcha('captcha' , $captchaOptions);        
        $this->addElement($captcha);*/
    
        // Bouton de validation
        $submitButton = new Zend_Form_Element_Submit('submit_reservation');
        $submitButton->setLabel("Valider");
        $submitButton->setValue("Valider");
        $submitButton->style = 'margin-left: 80px';
        $this->addElement($submitButton);

        // jeton
        $token   = new Zend_Form_Element_Hash('token', array('salt' => 'unique'));
        $this->addElement($token);
    }
}
